package com.aaa.controller;
import com.aaa.entity.Leixing;
import com.aaa.entity.Users;
import com.aaa.service.LeixingService;
import com.aaa.util.Constants;
import com.aaa.util.DefaultMsg;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * 角色管理控制器
 */
@RestController
@RequestMapping("/leixing")
public class LeixingController {


    @Resource
    private LeixingService leixingService;





    /**
     * 查询所有的角色信息
     * @return
     */
    @RequestMapping("/listAll")
    public PageInfo<Leixing> listAll(String keyword, Integer currentPage, Integer pageSize){
        PageHelper.startPage(currentPage,pageSize);
        QueryWrapper<Leixing> queryWrapper=new QueryWrapper<Leixing>();
        queryWrapper.like("lei",keyword);
        List<Leixing> list=leixingService.list(queryWrapper);

        PageInfo<Leixing> pageInfo=new PageInfo<Leixing>(list);
        return pageInfo;
    }


    /**
     * 保存或者修改角色信息
     * @param leixing
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    public DefaultMsg saveOrUpdate(Leixing leixing){
        DefaultMsg defaultMsg = new DefaultMsg();
        boolean b = leixingService.saveOrUpdate(leixing);
        if(!b){
            defaultMsg.setSuccess(0);
            defaultMsg.setError("操作失败");
        }
        return defaultMsg;
    }
    @RequestMapping("/delete")
    public boolean delete(Leixing leixing){
        boolean b = leixingService.removeById(leixing.getLid());
        return b;
    }
    public static void main(String[] args) {
        System.out.println(UUID.randomUUID().toString());
    }
}
